<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // Promise.all = function (promises) {
    //   return new Promise((resolve, reject) => {
    //     debugger
    //     let len = promises.length;
    //     let index = 0;
    //     let result = [];
    //     if (len === 0) {
    //       resolve([])
    //       return
    //     }
    //     for (let i = 0; i < len; i++) {
    //       Promise.resolve(promises[i]).then(data => {
    //         result[i] = data
    //         index++
    //         if (index >= len) resolve(result)
    //       }).catch(err => {
    //         reject(err)
    //       })
    //     }
    //   })
    // }
    let p1 = new Promise((resolve, reject) => {
      resolve(1)
    })
    let p2 = new Promise((resolve, reject) => {
      reject(2)
    })
    Promise.all([p1, p2]).then(res => {
      console.log(res)
    }).catch(err => {
      console.log(err) // 直接打印错误信息
    })
  </script>
</body>
</html>